<html>
<head><meta charset="utf-8"><title>Confusing &quot;conflicting implementations&quot; error message? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Confusing.20.22conflicting.20implementations.22.20error.20message.3F.html">Confusing &quot;conflicting implementations&quot; error message?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217560247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Confusing%20%22conflicting%20implementations%22%20error%20message%3F/near/217560247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Confusing.20.22conflicting.20implementations.22.20error.20message.3F.html#217560247">(Nov 22 2020 at 17:08)</a>:</h4>
<p>The following code:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">convert</span>::<span class="n">TryFrom</span><span class="p">;</span><span class="w"></span>

<span class="k">struct</span> <span class="nc">Test</span><span class="p">;</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="n">TryFrom</span><span class="o">&lt;</span><span class="n">U</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Test</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">U</span>: <span class="nb">AsRef</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u8</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Error</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">try_from</span><span class="p">(</span><span class="n">val</span>: <span class="nc">U</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="bp">Self</span><span class="p">,</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Error</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="bp">Self</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Gives the error:</p>
<div class="codehilite"><pre><span></span><code>error[E0119]: conflicting implementations of trait `std::convert::TryFrom&lt;_&gt;` for type `Test`:
  --&gt; src/main.rs:33:1
   |
33 | impl&lt;U&gt; TryFrom&lt;U&gt; for Test where U: AsRef&lt;[u8]&gt; {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl&lt;T, U&gt; TryFrom&lt;U&gt; for T
             where U: Into&lt;T&gt;;
</code></pre></div>
<p>This confused me because I thought there can't be a conflicting implementation at this point. But it was pointed out to me that it means there could be if someone else implements both <code>AsRef&lt;[u8]&gt;</code> and <code>From&lt;_&gt; for Test</code> for their own type. I admit this was something I wasn't even considering.</p>
<p>In fairness, now that I know the problem the error message does make sense to me. However it probably would have taken me longer to figure out what it meant without outside help. Even the <a href="https://doc.rust-lang.org/stable/error-index.html#E0119">Error Index</a> only gives simple examples for which the error message is much clearer.</p>
<hr>
<p>I stumbled upon this because I  was trying to change some <code>Into</code> code (with panics) to <code>TryInto</code>. But the automatic implementation of <code>TryFrom</code> means the same kinds of blanket implementation aren't possible.</p>



<a name="217562722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Confusing%20%22conflicting%20implementations%22%20error%20message%3F/near/217562722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Confusing.20.22conflicting.20implementations.22.20error.20message.3F.html#217562722">(Nov 22 2020 at 18:16)</a>:</h4>
<p><a href="https://stackoverflow.com/q/37347311/155423">How is there a conflicting implementation of <code>From</code> when using a generic type?</a></p>



<a name="217563143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Confusing%20%22conflicting%20implementations%22%20error%20message%3F/near/217563143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Confusing.20.22conflicting.20implementations.22.20error.20message.3F.html#217563143">(Nov 22 2020 at 18:27)</a>:</h4>
<p>I actually found that when I was trying to figure out the problem. It didn't help. Again, once I understood the problem I could see how that question is related. However, before that it wasn't at all obvious how. It was especially confusing because the <code>From</code> trait works but the <code>TryFrom</code> didn't.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>